package com.webcamtracker.ui;

import com.webcamtracker.ms2.ModelParameters;
import com.webcamtracker.ms2.SpaceTransforms;

import javax.swing.*;
import java.awt.*;

public class UIModelParameters extends JPanel {
    private ModelParameters modelParameters;
    private SpaceTransforms.SpaceCoordsTransform valueMapper;

    public void setModelParameters(ModelParameters modelParameters) {
        this.modelParameters = modelParameters;
    }

    public UIModelParameters() {
        super();
        valueMapper = new SpaceTransforms.SpaceCoordsTransform(new SpaceTransforms.SpaceCoords(0, 1), new SpaceTransforms.SpaceCoords(0, 255));
    }

    public void paint(Graphics graphics) {
        super.paint(graphics);
        if (modelParameters != null) {
            float[][] profileParams = modelParameters.profileParams;
            int x, y = 0;
            int size = 2;
            for (int i = 0; i < profileParams.length; i++) {
                x = 0;
                for (int j = 0; j < profileParams[i].length; j++) {
                    int value = (int) valueMapper.map(profileParams[i][j]);
                    graphics.setColor(new Color(value, value, value));
                    graphics.fillRect(x, y, size, size);
                    x += size;
                }
                y += size;
            }
        }
    }
}
